<template>
	<view class="content" :data-theme="theme">
		<view class="card" v-for="(item,index) in newDataValue" :key="index">
			<view class="item-contnet"
				style="display: flex;margin: 10rpx 0;font-weight: bold;">
				<view class="content-left1">
					租赁单号
				</view>
				<view class="content-right">
					{{item.id}}
				</view>
			</view>

			<view class="item-contnet" style="justify-content: space-between;">
				<view class="content-left">
					管理城市
				</view>
				<view class="content-right">
					{{item.operatyCity}}
				</view>
			</view>

			<view class="checke_list">
				<label class="uni-list-cell uni-list-cell-pd checke_item" v-for="(ele,indexn) in item.materialItemIds"
					:key="indexn">
					<view>
						<view class="item_top">
							<!-- 	<checkbox :value="JSON.stringify(item)" :iconColor="bgColor" :checked="ele.checked"
		     		class="round-checkbox" /> -->
							<view class="item_img">
								<u--image :showLoading="true" :src="ele.picture" width="80px" height="80px"></u--image>
							</view>
							<view class="item_right">
								<text v-if="item.brandName != null">[{{ele.brandName}}]</text>{{ele.materialName}}
								({{ele.specParam}})
								<view style="font-size: 30rpx;font-weight: normal;color: #808080;">
									<span>单价:{{ele.cost}}元</span>
									<span style="margin-left: 20rpx;">租借数量:{{ele.totalCount}}</span>
								</view>
							</view>

						</view>

						<!-- <view class="item_bottom" style="font-size: 30rpx;color: #808080;margin: 20rpx 0;">
							<span style="display: inline-block;margin-right: 30rpx;">库存数<span
									style="color: #000;">{{ele.allRemain}}</span>
							</span>
						</view> -->
						<view class="item_bottom">
							<view style="color: #888;margin-right: 10rpx;">退租数量</view>
							<uni-number-box :min="0" :max="ele.totalCount" v-model="ele.counts" />
						</view>
					</view>
				</label>
			</view>



		</view>

	</view>
</template>

<script>
	import {
		getMaterialsLisAPi
	} from "@/api/materials.js";
	import {
		setThemeColor
	} from '@/utils/setTheme';
	let app = getApp();
	export default {
		props: {
			applyData: {
				type: Array,
				default: ''
			}
			// tabIndex: {
			// 	type: Number,
			// 	default: 0
			// },
		},
		data() {
			return {
				bgColor: "#ffffff",
				theme: app.globalData.theme,
				materialForm: {
					auditState: 2, //审核状态：2通过
					size: 10,
					current: 1,
				},
				newDataValue: [],
				tabList: [{
					materialName: '物资名称1',
					materialsku: '3000L/桶',
					depotName: '大兴1仓',
					materialCode: 'BM13334324324',
					operatyCity: '北京A区',
					actualDeposit: 100, //实际退回押金
					applyTime: '2024-06-12 13:21:32',
					creator: '大粽子',
					lastUpdatedTime: '2024-06-12 12:25:35',
					lastUpdated: '小明',
				}],
				rentStateFliter: ['未使用', '租借中', '归还中', '已归还'],
				checkboxValue: [], // 选择的物资
				materialsData: [],
			}
		},
		mounted() {
			this.getMaterialsLis(); //获取物资列表
			setTimeout(() => {
				this.applyNewData();
			}, 200)
		},
		// created(){
		// 	setTimeout(() => {
		// 		this.applyNewData();
		// 	},200)
		// },

		methods: {
			// scrolltolowerFn() {
			// 	console.log('1221')
			// },
			returnMaterials(item) {
				this.$emit('returnMaterials', item);
			},
			checkboxChange(ele) {
				if (ele && ele.detail && ele.detail.value && ele.detail.value.length) {
					let checkboxValue1 = []
					for (var i = 0; i < ele.detail.value.length; i++) {
						checkboxValue1.push(Number(ele.detail.value[i]))
					}
					this.$set(this, 'checkboxValue', checkboxValue1)
					this.$emit('checkboxChange', checkboxValue1);
				} else {
					this.$emit('checkboxChange', ele);
				}

				//同步选择结果到父组件
				// let checkboxValue = ele;
				// this.$emit('checkboxChange', checkboxValue);
			},
			/** 退租物资重组 */
			applyNewData() {
				let newDataValue = [];

				for (let i = 0; i < this.applyData.length; i++) {
					let materItem = this.applyData[i].materialItemIds
					for (let j = 0; j < materItem.length; j++) {
						// 遍历解析后的 materialItemIds
						// 查找匹配的 id
						let foundItem = this.materialsData.find(item2 => item2.id == materItem[j].itemId);

						// // 如果找到匹配的项，则将 id 赋给第一个数组中的某个字段
						if (foundItem) {
							// 例如赋值给一个新的字段
							materItem[j].materialName = foundItem.materialName;
							materItem[j].picture = foundItem.picture;
							materItem[j].cost = foundItem.cost;
							materItem[j].totalCount = materItem[j].count;
							materItem[j].weight = foundItem.weight;
							materItem[j].specParam = foundItem.specParam;
							materItem[j].counts = 1;
						}
					}
				};
				this.newDataValue = this.applyData;
			},
			/** 获取物资列表 */
			getMaterialsLis() {
				getMaterialsLisAPi(this.materialForm).then((res) => {
					let info = res.data;
					this.materialsData = info.records;
				})
			},
		}
	}
</script>

<style lang="scss">
	.plain_bgColor {
		@include main_color(theme);
		@include main_bg_rgba_color(theme, 0.05);
		border: 1rpx solid;
	}

	.card {
		margin: 20rpx;
		background-color: #fff;
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		font-size: 29rpx;
	}

	.item-contnet {
		display: flex;
		justify-content: space-between;
		margin: 10rpx 0;

		.content-left {
			color: #9c9c9c;
			/* margin-right: 20rpx; */
		}
	}

	.checke_list {
		// width: 100%;
		margin: 20rpx;

		.checke_item {
			display: flex;
			flex-direction: column;
			// justify-content: space-around;
			// align-items: center;
			background-color: #f4f4f4;
			padding: 20rpx;
			margin-top: 10px;
			width: 100%;
			border-radius: 12rpx;

			.item_top {
				display: flex;
				// justify-content: space-around;
				// align-items: center;

				.item_img {
					margin-right: 10px;

					image {
						width: 50px;
						height: 70px;
					}

					;
					align-items: center;
				}

				.item_right {
					font-weight: bold;
					line-height: 20px;
					align-items: left;
				}
			}

			.item_bottom {
				display: flex;
				align-items: center;
				justify-content: flex-end;

				.counter {
					display: flex;
					justify-content: space-between;
					align-items: center;
					width: 100px;
					height: 30px;
					border: 1px solid #ccc;
					border-radius: 5px;
					overflow: hidden;
				}

				.counter text {
					width: 40px;
					height: 30px;
					text-align: center;
					line-height: 30px;
					font-size: 16px;
					color: #333;
				}
			}
		}
	}

	.footer-button {
		margin-top: 20rpx;
		margin-left: 10rpx;
		margin-right: 10rpx;
		padding-bottom: 20rpx;
	}
</style>